package org.dtrd.modules.record.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import org.dtrd.modules.device.entity.bean.bioland.SrcDataValue;
import org.dtrd.modules.device.entity.bean.xty.XtySugarRecord;
import org.dtrd.modules.doctor.entity.bean.DoctorIndexDynamicInfo;
import org.dtrd.modules.record.entity.bean.*;
import org.dtrd.modules.record.entity.po.DtrdEntRdSigninSugarValue;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 萧
 * @date:2021--16 8:23 下午
 **/
public interface ISugarRecordService extends IRecordService<DtrdEntRdSigninSugarValue> {

    void saveBiolandRecord(SrcDataValue srcDatavalue, Integer userId);

    DtrdEntRdSigninSugarValue getSugarValueLatest(Integer patientId);

    @Override
    default boolean saveOrUpdate(DtrdEntRdSigninSugarValue entity, Wrapper<DtrdEntRdSigninSugarValue> updateWrapper) {
        return IRecordService.super.saveOrUpdate(entity, updateWrapper);
    }

    /**
     * 根据 patientId 和类型查找最新的记录
     */
    DtrdEntRdSigninSugarValue getSugarValueLatestByPatientIdAndType(Integer patientId, Integer... types);

    boolean saveSugarRecord(SugarValueBean value);

    SugarChart getBloodSugarRecordsForCharts(int patientId, String startDate, String endDate, int sourceType);

    Integer getSugarRecordDateCount(Integer patientId, String startDate, String endDate, Integer sourceType);

    List<DailySugarRecordBean> getAllGroupedSugarValues(Integer patientId, String startDate, String startDate1, Integer page, Integer pageSize);

    Map getBloodSugarStatisticsByRecordType(int patientId, int type, String startTime, String endTime, int period);

    SugarValueBean selectLastRecordByPatientId(Integer patientId);

    /**
     * 同步 瞬感伴侣 蓝牙版 数据
     */
    boolean synchSGBLSugarList(List<SugarValueBean> list, Integer sourceType, Integer patientId);

    /**
     * 保存小糖医推送血糖记录
     *
     * @param recordList
     * @param userId
     */
    void saveXtySugarRecord(List<XtySugarRecord> recordList, Integer userId);

    /**
     * 查询指定小糖医血糖记录
     *
     * @param userId
     * @param recordType 记录类型
     * @param uploadTime 记录时间
     * @param timeType   时段类型 区分早午晚餐
     * @param sugar
     * @return
     */
    DtrdEntRdSigninSugarValue getXtySugarRecord(Integer userId, Integer recordType, String uploadTime, int timeType, Double sugar);

    /**
     * 查询周期内血糖平均值
     *
     * @param patientId
     * @param startOfWeek
     * @param endOfWeek
     * @param timeTypes   时段类型，如空腹：(1)、餐后(2,4,6)
     * @return
     */
    Float getAvgSugarRecord(Integer patientId, String startOfWeek, String endOfWeek, String timeTypes);

    /**
     * 获取对应时间段内的血糖记录，获取第一条数据
     * @param patientId
     * @param timeTypes
     * @return
     */
    Float getFirstSugarValue(Integer patientId, String timeTypes);

    /**
     * 计算时间段内血糖平均值
     *
     * @param patientId
     * @param startDate
     * @param endDate
     * @return
     */
    List<AvgRecordBean> getAvgSugarRecord(Integer patientId, String startDate, String endDate);

    /**
     * 微策血糖数据上报
     *
     * @param userId
     * @param value
     * @param timeType
     * @param measureTime
     * @param measureResult
     */
    void onWeiceSugarRecord(Integer userId, Float value, int timeType, String measureTime, Integer measureResult);

    /**
     * 分页获取每日血糖数据
     *
     * @param patientId
     * @param startDate
     * @param endDate
     * @param page
     * @param pageSize
     * @return
     */
    List<DailySugarRecordBean> getDailySugarRecord(Integer patientId, String startDate, String endDate, Integer page, Integer pageSize);

    /**
     * 查询瞬感设备的血糖记录
     */
    List<DailySugarRecordBean> getSGBLSugarRecord(Integer patientId, String startDate, String endDate, Integer page, Integer pageSize, Integer sourceType);

    /**
     * 查询血糖记录
     */
    SugarValueLineData pageSugarRecords(Integer patientId, Date startTime, Date endTime, Integer timeType, Integer sourceType, Integer orderType);

    PatientDailySugar getPatientDailySugar(Integer patientId, Date date);

    /**
     * 通过 patientIds 查询血糖列表
     */
    List<DtrdEntRdSigninSugarValue> listSugarValuesByPatientIds(List<Integer> patientIds);

    /**
     * 获取最新的6条血糖记录
     * @return
     */
    DoctorIndexDynamicInfo listPatientSugarValuesInfo(List<Integer> patientIds);

    List<DtrdEntRdSigninSugarValue> getLatestSugarValue(String patientIds, int... timeTypes);

    void handleAbnormalSugarValue(CheckinRecord record);
}
